<?php 
/**
 * 品牌控制器
 */
class BrandController extends CommonController{
	private $model;
	
	public function __init(){
		parent::__init();
	    $this->model = K('Brand');
	}
    /**
     * 首页
     */
    public function index(){
    		$order = "bid ASC";
		$check = 0;
    		if (isset($_POST['sort_by_bsort'])){    			
    			$order = 'bsort DESC';
			$check = 1;
    		}
		$this->assign('check', $check);
    		$this->assign('data', $this->model->order("{$order}")->all());
       	$this->display(); 
    }
	
	// 添加
	public function add(){
		if (IS_POST){
			if (!$this->model->addData()) {
				$this->error($this->model->error);
			}
			$this->success("添加商品品牌成功", U('Index'));
		}
	    $this->display();
	}
	
	// 修改
	public function edit(){
		if (IS_POST){
			if (!$this->model->editData()) {
				$this->error($this->model->error);
			}
			$this->success("修改商品品牌成功", U('Index'));
		}
		$bid = Q('get.bid', 0, 'intval');
		$this->assign('oldData', $this->model->where("bid={$bid}")->find());
	    $this->display();
	}
	
	// 删除
	public function del(){
	    $bid = Q('get.bid', 0, 'intval');
		if (!$this->model->where("bid={$bid}")->delete()){
			$this->error($this->model->error);
		}
		$this->success("删除商品品牌成功", U('Index'));
	}
	
	// 上传
	public function ajaxUpload()
	{
	   $upload = new Upload('Upload/Content/' . date('y/m'));
	   $file = $upload->upload();
	   if (empty($file)) {
	       $this->ajax('上传失败');
	   } else {
	       $data = $file[0];
	       $this->ajax($data);
	   }
	}
 }
 
 
 
 
 
 
 
 
 
 
 


 ?>